
 

package control;

import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JTable;
import model.Account;
import model.Share;
import model.StockData;
import model.Time;
import view.AccountView; 
import view.StatisticChartView;

/**
 * StockApp.java
 * @author Diego Schmaedech
 * @version 1.0
 * @since Release Beta
 * @link  http://code.google.com/p/economylabs
 * Created on August 2, 2008, 2:34 AM
 */
public class StockApp extends JFrame {

    /** Creates new form StockApp */
    public StockApp() {
        
        loadConfiguration();
        account = new Account( tableAccount );     
        share = new Share( tableShare );
        time = new Time( tableTime );
        initComponents();
        PriceChartController chartController = new PriceChartController(account, share, time);
        StatisticChartView chartViewer  = new StatisticChartView( account, share, time );
         
        chartViewer.pack();
        chartViewer.setLocation(0, 500);  
        chartViewer.setVisible(true);
        
        chartController.pack();
         
        chartController.setLocation(550, 0); 
        
        
        chartController.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        //AccountController jpTransaction = new AccountController( account, share, time );
        jPanel1 =  new AccountController( account, share, time );
        //AccountView jpAccount = new AccountView( account );
        jPanel2 = new AccountView( account );
        //ShareController jpShareController = new ShareController(account, share, time);
        jPanel3 = new ShareController(account, share, time);
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        cutMenuItem = new javax.swing.JMenuItem();
        copyMenuItem = new javax.swing.JMenuItem();
        pasteMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Stock Manager : Our Time "+ new Date());
        setBackground(new java.awt.Color(254, 254, 254));
        setResizable(false);

        //jPanel1.add(jpTransaction);
        jPanel1.setBackground(new java.awt.Color(214, 233, 249));

        //jPanel2.add(jpAccount);
        jPanel2.setBackground(new java.awt.Color(254, 253, 152));

        //jPanel3.add(jpShareController);
        jPanel3.setBackground(new java.awt.Color(254, 254, 254));

        menuBar.setBackground(new java.awt.Color(254, 254, 254));
        menuBar.setEnabled(false);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("control/Bundle"); // NOI18N
        fileMenu.setText(bundle.getString("StockApp.fileMenu.text")); // NOI18N

        openMenuItem.setText(bundle.getString("StockApp.openMenuItem.text")); // NOI18N
        fileMenu.add(openMenuItem);

        saveMenuItem.setText(bundle.getString("StockApp.saveMenuItem.text")); // NOI18N
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText(bundle.getString("StockApp.saveAsMenuItem.text")); // NOI18N
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setText(bundle.getString("StockApp.exitMenuItem.text")); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText(bundle.getString("StockApp.editMenu.text")); // NOI18N

        cutMenuItem.setText(bundle.getString("StockApp.cutMenuItem.text")); // NOI18N
        editMenu.add(cutMenuItem);

        copyMenuItem.setText(bundle.getString("StockApp.copyMenuItem.text")); // NOI18N
        editMenu.add(copyMenuItem);

        pasteMenuItem.setText(bundle.getString("StockApp.pasteMenuItem.text")); // NOI18N
        editMenu.add(pasteMenuItem);

        deleteMenuItem.setText(bundle.getString("StockApp.deleteMenuItem.text")); // NOI18N
        editMenu.add(deleteMenuItem);

        menuBar.add(editMenu);

        helpMenu.setText(bundle.getString("StockApp.helpMenu.text")); // NOI18N

        contentsMenuItem.setText(bundle.getString("StockApp.contentsMenuItem.text")); // NOI18N
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setText(bundle.getString("StockApp.aboutMenuItem.text")); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new StockApp().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem copyMenuItem;
    private javax.swing.JMenuItem cutMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JMenuItem pasteMenuItem;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    // End of variables declaration//GEN-END:variables

    private StockData modelAccount;
    private StockData modelShare;
    private StockData modelTime;
    private JTable tableAccount;
    private JTable tableShare;
    private JTable tableTime; 
    Account account;     
    Share share;
    Time time;
    
    public void loadConfiguration(){          
        
        this.modelShare = new StockData("resources/config/share.txt");        
        this.tableShare = new JTable();
        this.tableShare.setModel(modelShare);
         
        this.modelTime = new StockData("resources/config/time.txt");       
        this.tableTime = new JTable();
        this.tableTime.setModel(modelTime);
        this.tableTime.createDefaultColumnsFromModel();
          
        this.modelAccount = new StockData("resources/config/account.txt");
        this.tableAccount = new JTable();
        this.tableAccount.setModel(modelAccount);
        this.tableAccount.createDefaultColumnsFromModel();
        /*
        Object[][] fopShare = new Object[tableShare.getModel().getRowCount()][tableShare.getModel().getColumnCount()];
          for(int x=0;x<tableShare.getModel().getRowCount();x++){
              for(int y=0;y<tableShare.getModel().getColumnCount();y++){
              //System.out.print(tableShare.getModel().getValueAt(x, y)+ " ");
              fopShare[x][y]= tableShare.getModel().getValueAt(x, y);
              //System.out.print(fopShare[x][y]+ " ");
        }  
              //System.out.println();
        }
          */ 
    }
 
   
    
}
